package com.example.myweb.Domain.Entity;

import com.example.myweb.Domain.Entity.Attachment;
import javax.persistence.AttributeConverter;
import javax.persistence.Converter;

@Converter(autoApply = true)
public class AttachmentTypeConverter implements AttributeConverter<Attachment.AttachmentType, String> {

    @Override
    public String convertToDatabaseColumn(Attachment.AttachmentType attribute) {
        return (attribute == null) ? null : attribute.name();
    }

    @Override
    public Attachment.AttachmentType convertToEntityAttribute(String dbData) {
        if (dbData == null || dbData.trim().isEmpty()) {
            return null;
        }
        return Attachment.AttachmentType.valueOf(dbData.toUpperCase());
    }
}